package com.circulardependence.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.circulardependence.entity.Personal;
import com.circulardependence.mapper.PersonalMapper;
import com.circulardependence.service.MyaddressService;
import com.circulardependence.service.PersonalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * Created by IntelliJ IDEA2021.3
 * @Author: Tenghw
 * @Date: 2022/08/24  22:42
 * @Description:
 */
@Slf4j
@Service("personalService")
@SuppressWarnings("all")
@Transactional(rollbackFor = Exception.class)
public class PersonalServiceImpl implements PersonalService {

    @Autowired
    PersonalMapper personalMapper;

    @Autowired
    MyaddressService myaddressService;


    @Override
    public int insertSelective(Personal personal) {
        return personalMapper.insertSelective(personal);
    }

    @Override
    public int deleteById(Integer id) {
        return personalMapper.deleteById(id);
    }

    @Override
    public int updateNameByIdAndCamp(String name, Integer id, String camp) {
        return updateNameByIdAndCamp(name, id, camp);
    }

    @Override
    public Personal selectOneById(Integer id) {
        return personalMapper.selectOneById(id);
    }

    //mybatis-plus实现分页查询
    @Override
    public List<Personal> findByCampPages(Personal personal) {
        Page<Personal> page = new Page<>();
        page.setCurrent(1);//当前页码
        page.setSize(2);//一页多少条数据
        try {
            IPage<Personal> personalIPage = personalMapper.selectAllByCampPage(page, personal);
            List<Personal> personalList = personalIPage.getRecords();
            return personalList;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
